package com.gorkr.offer.array;

import org.junit.jupiter.api.Test;

import javax.swing.tree.TreeNode;

/**
 * @author gorkr
 * @date 2022/07/26 22:28
 **/
public class E18ShanChuLianBiaoDeJieDianIcof {

    class ListNode {
        int val;
        ListNode next;
        ListNode(int x) {
            val = x;
        }
    }

    public ListNode deleteNode(ListNode head, int val) {
        ListNode h = new ListNode(Integer.MIN_VALUE);
        h.next=head;

        ListNode pre = h;
        ListNode p = h.next;

        while(p!=null){
            if(p.val==val){
                pre.next=p.next;
                return h;
            }else {
                pre = p;
                p = p.next;
            }
        }
        return h;
    }

    @Test
    public void test(){
        ListNode a = new ListNode(-3);
        a.next = new ListNode(5);
        a.next.next = new ListNode(-99);
        ListNode head = new ListNode(-1);
        head.next = a;

        ListNode listNode1 = deleteNode(head, -3);
        System.out.println(listNode1);

    }
}
    